package com.tyrone.leetcode.weekgame;

import java.util.Arrays;
import java.util.Map;

/**
 * @author yelong.xie
 * @date 2024/2/11 10:31
 */
public class ModifiedMatrix {
    public static void main(String[] args) {
        Solution solution = new Solution();
        int[][] ints = solution.modifiedMatrix(new int[][]{{1, 2, -1}, {4, -1, 6}, {7, 8, 9}});
        System.out.println(Arrays.toString(ints));
    }

    static class Solution {
        public int[][] modifiedMatrix(int[][] matrix) {
            int m = matrix.length;
            int n = matrix[0].length;
            int[] colMax = new int[n];
            Arrays.fill(colMax, Integer.MIN_VALUE);
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    colMax[i] = Math.max(colMax[i], matrix[j][i]);
                }
            }
            for (int i = 0; i < m; i++) {
                for (int j = 0; j < n; j++) {
                    if (matrix[i][j] == -1) matrix[i][j] = colMax[j];
                }
            }
            return matrix;
        }
    }
}
